﻿namespace WpfDemoControlLibrary
{
    using System.Collections.ObjectModel;
    using System.ComponentModel;

    /// <summary>
    /// The view model for the UserControl "PersonUserControl".
    /// </summary>
    public class PersonUserControlViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// All created persons
        /// </summary>
        private ObservableCollection<Person> persons = new ObservableCollection<Person>();

        // The current values of the form
        private string firstname = "";
        private string name = "";
        private string nationality;
        private string[] countries;

        public PersonUserControlViewModel()
        {
            // Set the avaiable items for the combobox.
            this.countries = new string[] { "Switzerland", "Germany", "France", "Italy" };
        }

        #region INotifyPropertyChanged Members

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        public string Firstname
        {
            get
            {
                return this.firstname;
            }

            set
            {
                this.firstname = value;
                this.OnPropertyChanged("Firstname");
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
                this.OnPropertyChanged("Name");
            }
        }

        public string Nationality
        {
            get
            {
                return this.nationality;
            }

            set
            {
                this.nationality = value;
                this.OnPropertyChanged("Nationality");
            }
        }

        public ObservableCollection<Person> Persons
        {
            get
            {
                return this.persons;
            }

            set
            {
                this.persons = value;
                this.OnPropertyChanged("Persons");
            }
        }

        public string[] Countries
        {
            get
            {
                return this.countries;
            }

            set
            {
                this.countries = value;
                this.OnPropertyChanged("countries");
            }
        }
    }
}
